package com.lhf.springcloud.service.impl;

import com.lhf.springcloud.DAO.teacher.TeacherBasicMapper;
import com.lhf.springcloud.Entity.teacher.TeacherBasicData;
import com.lhf.springcloud.service.TeacherBasicDataService;
import com.lhf.springcloud.utils.XmlUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TeacherBasicDataImpl implements TeacherBasicDataService {
    @Autowired
    TeacherBasicMapper teacherBasicMapper;
    @Override
    public Map findAllTeacherBasicData(Integer startPage,Integer endPage) {
        List<TeacherBasicData> allTeacherBasicData = teacherBasicMapper.findAllTeacherBasicData(startPage,endPage);
        int i = teacherBasicMapper.accountTeacher();
        Map map=new HashMap<>();
        map.put("data",allTeacherBasicData);
        map.put("count",i);
        return map;
    }

    @Override
    public Map findByIdCard(String idCard,String teacherName,Integer page,Integer limit) {
        List<TeacherBasicData> byTeacherIdCard = teacherBasicMapper.findByTeacherIdCard(idCard,teacherName,page,limit);
        int i = teacherBasicMapper.accountTeacher();
        Map map=new HashMap<>();
        map.put("data",byTeacherIdCard);
        map.put("count",i);
        return map;
    }

    @Override
    public void updateData(String value, String id, String field) {
        String teacherBasicMap = XmlUtils.getMapperPropertyByColumn("mapping/TeacherBasicDataMapper.xml", "TeacherBasicMap", field);
        teacherBasicMapper.updateTeacherData(value,id,teacherBasicMap);
    }

    @Override
    public void addCourse(List<TeacherBasicData> list1) {
        if (list1.size()>0){
            for (int i=0;i<list1.size();i++){
                teacherBasicMapper.addTeacherCourse(list1.get(i));
            }
        }
    }
}
